package org.dromara.system.controller.system;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.constant.MachineConstant;
import org.dromara.system.domain.bo.SimMallNameBo;
import org.dromara.system.domain.vo.SimMallNameVo;
import org.dromara.system.service.ISimMallNameService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城名称
 *
 * @author Lion Li
 * @date 2025-08-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/mallName")
public class    SimMallNameController extends BaseController {

    private final ISimMallNameService simMallNameService;

    /**
     * 查询商城名称列表
     */
//    @SaCheckPermission("system:mallName:list")
    @GetMapping("/list")
    public TableDataInfo<SimMallNameVo> list(SimMallNameBo bo, PageQuery pageQuery) {
        return simMallNameService.queryPageList(bo, pageQuery);
    }


    //查询商城名称 小程序
    @GetMapping("/listReception")
    public TableDataInfo<SimMallNameVo> listReception(SimMallNameBo bo, PageQuery pageQuery) {
        bo.setStatus(MachineConstant.NUMBER.ONE);
        return simMallNameService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商城名称列表
     */
//    @SaCheckPermission("system:mallName:export")
    @Log(title = "商城名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SimMallNameBo bo, HttpServletResponse response) {
        List<SimMallNameVo> list = simMallNameService.queryList(bo);
        ExcelUtil.exportExcel(list, "商城名称", SimMallNameVo.class, response);
    }

    /**
     * 获取商城名称详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:mallName:query")
    @GetMapping("/{id}")
    public R<SimMallNameVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(simMallNameService.queryById(id));
    }

    /**
     * 新增商城名称
     */
//    @SaCheckPermission("system:mallName:add")
    @Log(title = "商城名称", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SimMallNameBo bo) {
        return toAjax(simMallNameService.insertByBo(bo));
    }

    /**
     * 修改商城名称
     */
//    @SaCheckPermission("system:mallName:edit")
    @Log(title = "商城名称", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SimMallNameBo bo) {
        return toAjax(simMallNameService.updateByBo(bo));
    }

    /**
     * 删除商城名称
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:mallName:remove")
    @Log(title = "商城名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(simMallNameService.deleteWithValidByIds(List.of(ids), true));
    }
}
